var t = getApp();
var iconsUrl=t.globalData.iconsUrl
Component({
    properties: {},
    data: {
      iconsUrl:t.globalData.iconsUrl,
      contract_info: {},
      hidden_login: !0,
    },
    ready: function() {
        
    },
    methods: {
      getUserProfile: function(e) {
        console.log(t.globalData);
        var that = this
        if (!wx.getStorageSync('userinfo')) {
          // 微信自带登陆方法
          wx.login({
            // 成功回调
            // es6新写法==success(res){}
            success: res => {
              console.log(res.code);
              var o={
                  code:res.code,
                  // 固定写法
                  platform:'wxapp'
                }
                // 微信自带提示框
                // 只能改选项的颜色、文字
                wx.showModal({
                  title:'提示',
                  content:'获取你的昵称、头像、地区及性别',
                  success(e){
          
                    console.log(e)
                    // 用户选择了确定
                    if (e.confirm) {
                      // 微信自带获取用户
                      wx.getUserProfile({
                        desc: "获取你的昵称、头像、地区及性别", // 不写不弹提示框
                        success(ress) {
                          console.log(ress);
                            o.iv=ress.iv
                            o.da=ress.encryptedData
                            console.log(o)
                          
                            t.globalData.userInfo = ress.userInfo
                            console.log(t.globalData.userInfo);
                            wx.setStorageSync('userinfo', ress.userInfo);
                            t.request('/login',o,function(s){
                                t.globalData.token = s.result.token;
                                wx.setStorageSync('token', s.result.token);
                                t.request('/cars/list',{},function(e){
                                  if (e.code==200) {
                                    if (e.result.total>0) {
                                        t.globalData.carList = e.result
                                        wx.setStorageSync('carList', e.result);
                                    }else{
                                        wx.setStorageSync('carList', "");
                                        that.setData({
                                          hidden_login: !0
                                        });
                                        wx.navigateTo({
                                          url: '/pages/login/login',
                                        })
                                    }
                                  }
                              })
                            })
                            that.setData({
                              hidden_login: !0
                            });
                        },
                        fail(e){
                          console.log(e);
                        }
                    })
                    }
                  }
                })
              wx.getLocation({
                  success:function(res){
                      console.log(res);
                      t.globalData.loc = res
                  }
              })
            }
          })
        }else{
          wx.navigateTo({
            url: '/pages/login/login',
          })
          that.setData({
            hidden_login: !0
          });
        }
      },
      hidden: function() {
          this.setData({
              hidden_login: !0,
              bind_qrcode: !0
          });
      },
      show_login: function(n) {
          this.setData({
              hidden_login: !1
          });
      },
    }
});